import { ref } from 'vue'
import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration'
dayjs.extend(duration)


export const pyZtOptions = ref<any[]>([])

import { dictionaryTeacher } from '/@/api/system-manage/teacher-info'
import { setAuthCache, getAuthCache } from '/@/utils/auth'

interface DictionaryInfo {
    value: any[];
}

// 数据字典
export const getDictionaryList = async (groupCode, dictionaInfo?: DictionaryInfo) => {
    try {
        let Data = getAuthCache("dictionaInfo") || {};
        if (Data[groupCode]?.length) {
            if (dictionaInfo) {
                dictionaInfo.value = Data[groupCode]
            }
            return Data[groupCode]
        }
        const { data } = await dictionaryTeacher({ pageSize: 0 })
        data.forEach(element => {
            element.label = element.dictName
            element.value = element.dictCode
            if (!Data[element.groupCode]) {
                Data[element.groupCode] = []
            }
            Data[element.groupCode].find(item => item.value === element.dictCode) || Data[element.groupCode].push(element)
        })
        if (dictionaInfo) dictionaInfo.value = Data[groupCode]
        setAuthCache("dictionaInfo", Data)
        return Data[groupCode]
    } catch (error) {
        if (dictionaInfo) {
            dictionaInfo.value = []
        }
        return []
    }
}

getDictionaryList('pyListZtCode', pyZtOptions)





export const evaluation = ref([
    {
        title: '序号',
        dataIndex: 'index',
        key: 'index',
        align: 'center',
        width: 80,
        fixed: true,
    },
    {
        title: '科目代码',
        dataIndex: 'kmdm',
        key: 'kmdm',
        align: 'center',
    },
    {
        title: '题目类型    ',
        dataIndex: 'tmlx',
        key: 'tmlx',
        align: 'center',
    },
    {
        title: '题目编号',
        dataIndex: 'tmbh',
        key: 'tmbh',
        align: 'center',
    },
    {
        title: '评阅得分',
        dataIndex: 'pyZdf',
        key: 'pyZdf',
        align: 'center',
    },
    {
        title: '评阅开始时间',
        dataIndex: 'pyKssj',
        key: 'pyKssj',
        align: 'center',
    },
    {
        title: '评阅结束时间',
        dataIndex: 'pyTjsj',
        key: 'pyTjsj',
        align: 'center',
    },
    {
        title: '评阅阶段',
        dataIndex: 'zpDataFlag',
        key: 'zpDataFlag',
        align: 'center',
        customRender: ({ text }) => {
            if (text) {
                return '正评阅'
            } else {
                return '试评阅'
            }
        },
    },
    {
        title: '评卷时长',
        dataIndex: 'pyHs',
        key: 'pyHs',
        align: 'center',
        customRender: ({ text }) => {
            let time = +new Date('2023-01-01') + 1000 * text
            return dayjs.duration(time || 1000).format('HH:mm:ss')
        },
    },
    {
        title: '评阅状态',
        dataIndex: 'pyZt',
        key: 'pyZt',
        align: 'center',
        customRender: ({ text }) => {
            return pyZtOptions.value.find(item => item.dictCode === text)?.dictName
        },
    },
    {
        title: '操作',
        dataIndex: 'operation',
        key: 'operation',
        align: 'center',
        fixed: 'right',
    }
])



import { selectKmpyjdOption } from '/@/views/home/index/index'

export const labelOption = ref([
    // {
    //   name: '试题类型',
    //   key: 'stLx',
    //   labelWidth: 70,
    //   inputWidth: 150,
    //   selectOption: [
    //     { label: '主观题', value: 'ZGT' },
    //     { label: '客观题', value: 'KGT' },
    //   ],
    // },
    {
        name: '评阅阶段',
        key: 'zpDataFlag',
        labelWidth: 80,
        inputWidth: 150,
        type: 'Radio',
        selectOption: selectKmpyjdOption,
        isNotReset: true,
    },
    // { name: '评卷区间分数', key: 'startScore', inputWidth: 120 },
    // { name: '', key: 'endScore', inputWidth: 120 },
    // {
    //   name: '评分时间',
    //   key: 'isMissExam',
    //   labelWidth: 80,
    //   type: 'Time',
    //   changefunction: key => {
    //     filterOption.value['beginTime'] = moment(filterOption.value.isMissExam[0].$d).format(
    //       'YYYY-MM-DD HH:mm'
    //     )
    //     filterOption.value['endTime'] = moment(filterOption.value.isMissExam[1].$d).format(
    //       'YYYY-MM-DD HH:mm'
    //     )
    //     delete filterOption.value.isMissExam
    //   },
    //   inputWidth: 250,
    // },
    {
        name: '评阅状态',
        labelWidth: 80,
        key: 'pyZt',
        selectOption: pyZtOptions,
        inputWidth: 150,
    },
    
    { name: '评阅得分', key: 'pyZdf', labelWidth: 80,inputWidth: 120 },
])